<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改资料</h1>
		</header>
		<div class="mui-content" id="main">
			<form class="mui-input-group" id="form">
				<div class="mui-input-row">
					<label>学号</label>
					<input type="text" name="stuId" readonly="readonly" :value="stuId">
				</div>
				<div class="mui-input-row">
					<label>邮箱</label>
					<input type="text" name="email" :value="email">
				</div>
				<div class="mui-input-row">
					<label>昵称</label>
					<input type="text" :value="nickName" id="nickName" name="nickName">
				</div>
				
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-danger" onclick="loginOut()">注销账号</button>
					<button type="button" class="mui-btn mui-btn-primary" onclick="update()">确认修改</button>
				</div>
				
			</form>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/const.js" ></script>
		<script type="text/javascript" src="../js/request.js" ></script>
		<script type="text/javascript" src="../js/user_service.js" ></script>
		<script type="text/javascript" src="../js/vue.min.js" ></script>
		<script type="text/javascript" src="../js/jquery-1.8.3.min.js" ></script>
		<script type="text/javascript" src="../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			
				function getDefaultData(){
				return{
					nickName:'',
					stuId:'',
					email:'',
					userface:'',
					userface_path:USER_FACE_PATH+'/'
				}
			}
				
					var data_detail = new Vue({
				el:'#main',
				data:getDefaultData(),
				methods:{
					resetData:function(){//重置数据
						Object.assign(this.$data,getDefaultData());
					},
//					open_detail:function(item){
//						//打开演员详情页面
//						mui.openWindow({
//							id:'cast-detail',
//							url:'./cast-detail.html',
//							extras:{
//								castId:item.id
//							}
//						});
//					}
				}
			});
			
			
				mui.plusReady(function(){
//					console.log(JSON.stringify(app.getState()))
					var self = plus.webview.currentWebview();
				//添加hide事件，清空页面数据，滚到最顶部
				self.addEventListener('hide',function(e){
					window.scrollTo(0,0);
					data_detail.resetData();
				},false);
			
					});
		
			window.addEventListener("userId", function(event) {
				plus.nativeUI.showWaiting('加载中',{
					width:'100px',
					height:'100px'
				});
				var res = userService.get_user_info();
				plus.nativeUI.closeWaiting();
				if(res.resultCode ==REQUEST_SUCCESS_CDOE){
					console.log(JSON.stringify(res.data));
				data_detail.stuId = res.data.stuId;
				data_detail.email = res.data.email;
				data_detail.nickName = res.data.nickName;
					return;
				}
				plus.nativeUI.toast(res.msg);
				
								
				
				
			});
			
			function update(){
				var wt = plus.nativeUI.showWaiting('正在提交数据');
				var res = userService.update_user_info($("#form").serialize());
				plus.nativeUI.toast(res.msg);
				wt.close();
				if(res.resultCode ==REQUEST_SUCCESS_CDOE){
					var state = app.getState();
					state.userNickeName =$("#nickName").val();
					app.setState(state);
					var list = plus.webview.currentWebview().opener();
					//触发列表界面的自定义事件（refresh）,从而进行数据刷新  
					mui.fire(list, 'refresh');
					mui.back();
				}
				
				
			}
			
			function loginOut() {
				app.removeState();
				userService.login_out();
				var list = plus.webview.currentWebview().opener();
				//触发列表界面的自定义事件（refresh）,从而进行数据刷新  
				mui.fire(list, 'refresh');
				mui.back();
				
			}
		</script>
	</body>

</html>